local skel = fk.CreateSkill {
  name = "emo__beiqi",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__beiqi"] = "悲奇",
  [":emo__beiqi"] = "锁定技，游戏开始时，你每有一张黑色/红色牌，你获得一张点数花色相同的【杀】/【闪】的复制，这些牌称为“泪”且不计入手牌上限。当一张“泪”进入弃牌堆时，你获得锦囊和装备牌各一张。",

  ["@@beiqi_tear"] = "泪",
}

skel:addEffect(fk.GameStart, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local get = {}
    for _, id in ipairs(player:getCardIds("he")) do
      local c = Fk:getCardById(id)
      if c.color ~= Card.NoColor then
        table.insert(get, room:printCard(c.color == Card.Black and "slash" or "jink", c.suit, c.number).id)
      end
    end
    if #get > 0 then
      room:obtainCard(player, get, false, fk.ReasonPrey, player, skel.name, "@@beiqi_tear")
    end
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId):getMark("@@beiqi_tear") ~= 0 then
            return true
          end
        end
      end
    end
  end,
  trigger_times = function (self, event, target, player, data)
    local n = 0
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId):getMark("@@beiqi_tear") ~= 0 then
            n = n + 1
          end
        end
      end
    end
    return n
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getCardsFromPileByRule(".|.|.|.|.|trick", 1, "allPiles")
    local id = room:getCardsFromPileByRule(".|.|.|.|.|equip", 1, "allPiles")[1]
    if id then table.insert(ids, id) end
    if #ids > 0 then
      room:obtainCard(player, ids, false, fk.ReasonJustMove, player, skel.name)
    end
  end,
})

skel:addEffect("maxcards", {
  exclude_from = function (self, player, card)
    if player:hasSkill(skel.name) then
      return card:getMark("@@beiqi_tear") ~= 0
    end
  end,
})

return skel
